$(function(){
	var flag = true;
	$("input[name='type_id_box']").each(function() {
		if (!$(this).prop("checked")) {
			flag = false;
		}
	});
	$("#type_box_all").prop("checked", flag);
});

function submitPageByChecked(obj) {
	if(UTIL.checkButton(obj)) {
		// 将勾选和未勾选的id拼凑成字符串
		var checkedIds = "";
		var unCheckedIds = "";
		$("input[name='id_box']").each(function() {
			if($(this).prop("checked")) {
				checkedIds += $(this).val() + ",";
			} else {
				unCheckedIds += $(this).val() + ",";
			}
		});
		
		if(checkedIds) {
			checkedIds = checkedIds.substring(0, checkedIds.length-1);
		}
		if(unCheckedIds) {
			unCheckedIds = unCheckedIds.substring(0, unCheckedIds.length-1);
		}
		
		// 调用后台接口维护
		var param = 
			{
				"checkedIds" : checkedIds,
				"unCheckedIds" : unCheckedIds
			};
		var keyword = $("#keyword").val();
		API.atomSymptomCheckPageByChecked(param, function(res) {
			if(res.code == 0) {
				getCheckedList(keyword);
			} else {
				alert(res.desc);
			}
		});
		
		UTIL.releaseButton(obj);
		return true;
	}
}

function getCheckedList(keyword) {
	var hrefStr = "/vocab/atom_symptom_checked_list.htm?keyword=" + keyword;
	location.href = hrefStr;
}

function setType1(obj) {
	var param = {id:$(obj).val()};
	if($(obj).prop("checked")) {
		param.type = "1";
	} else {
		param.type = "0";
	}
	API.atomSymptomSetType(param, function(res) {
		if(res.code == 0) {
			
		} else {
			alert(res.desc);
		}
	});
}

function atomSymptomType1Export(obj) {
	if(UTIL.checkButton(obj)) {
		window.location.href="/vocab/atom_symptom_type1_export.htm";
		UTIL.releaseButton(obj);
	}
}

function selectAllTypeBox() {
	if ($("#type_box_all").prop("checked")) {
		$("input[name='type_id_box']").prop("checked", true);
	} else {
		$("input[name='type_id_box']").prop("checked", false);
	}
	$("input[name='type_id_box']").each(function() {
		setType1(this);
	});
}